package com.example.springboot.controller;


import com.example.springboot.pojo.LeaveRequest;
import com.example.springboot.pojo.PageBean;
import com.example.springboot.pojo.Result;
import com.example.springboot.service.LeaveRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/leave")
public class LeaveRequestController {

    @Autowired
    private LeaveRequestService leaveRequestService;

    @GetMapping("/getList")
    public Result<PageBean<LeaveRequest>> getList(Integer pageNum,Integer pageSize){
        PageBean<LeaveRequest> pb = leaveRequestService.getList(pageNum,pageSize);
        return Result.success(pb);
    }

    @GetMapping("/getByWorkerId")
    public Result<PageBean<LeaveRequest>> getByWorkerId(Integer pageNum,Integer pageSize,String workerId){
        PageBean<LeaveRequest> pb = leaveRequestService.getByWorkerId(pageNum,pageSize,workerId);
        return Result.success(pb);
    }

    @PostMapping("/addRequest")
    public Result<?> addRequest(String workerId,String detail,String start,String end){
        leaveRequestService.addRequest(workerId,detail,start,end);
        return Result.success();
    }

    @PutMapping("/pass")
    public Result<?> pass(Integer id){
        leaveRequestService.pass(id);
        return Result.success();
    }

    @PutMapping("/refuse")
    public Result<?> refuse(Integer id){
        leaveRequestService.refuse(id);
        return Result.success();
    }
}
